package com.zhan.utils.model;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * @author 白尚兵
 * @date 2019/11/27 10:55
 **/
@Data
public class CurrentUserInfo {
    @ApiModelProperty("用户id")
    private Long id;
    @ApiModelProperty("员工id")
    private Long empId;
    @ApiModelProperty("员工姓名")
    private String username;
    @ApiModelProperty("手机")
    private String phone;
    @ApiModelProperty("部门id")
    private Long departmentId;
    @ApiModelProperty("部门名称")
    private String departmentName;
    @ApiModelProperty("部门全称 （格式-/部门1/部门2/.../部门n)")
    private String fullDepartmentName;
    @ApiModelProperty("角色id")
    private Long roleId;
    @ApiModelProperty("角色名")
    private String roleName;
    @ApiModelProperty("上班普席工号")
    private String generalCode;
    @ApiModelProperty("抢班普席工号")
    private String snatchCode;
    @ApiModelProperty("密码状态（0-未修改密码，1-以修改密码）")
    private Integer passwordState = 0;
    @ApiModelProperty("登录时间")
    private Date loginTime;
    @ApiModelProperty(value = "状态（0-正常，1-禁用，99-其他）", allowableValues = "0,1,99")
    private Integer userState;
    @ApiModelProperty("排序字段")
    private Integer sortCount;
    /**
     * 数据权限类型
     */
    private DataPermissionType dataPermissionType;
    /**
     * 当前部门及其所有下级部门的id集合
     */
    private Set<Long> departmentIds;

    /**
     * 操作权限列表
     */
    private List<String> operationCodeList;

    /**
     * 获得当前用户数据权限类型
     */
    public DataPermissionType getDataPermissionType() {
        if (dataPermissionType == null) {
            if (operationCodeList != null) {
                for (String operationCode : operationCodeList) {
                    if (DataPermissionType.ALL_DATA.name().equals(operationCode)) {
                        this.dataPermissionType = DataPermissionType.ALL_DATA;
                        break;
                    }
                }
            }
        }
        if (dataPermissionType == null) {
            this.dataPermissionType = DataPermissionType.DEPARTMENT_DATA;
        }
        return this.dataPermissionType;
    }

    public enum DataPermissionType {
        /**
         * 全局数据
         */
        ALL_DATA,
        /**
         * 部门数据
         */
        DEPARTMENT_DATA;
    }
}
